package com.control;

import com.dao.StudentDao;

import javax.naming.NamingException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * @author :wn
 * @program : 项目五登录界面
 * @descript :
 * @create :2020-11-06 20:18
 */
@WebServlet(value = "/information")
public class MainControl extends HttpServlet {
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        resp.setContentType("text/html,charset=utf-8");
        String[] sName = req.getParameterValues("name");
        String []sAge=req.getParameterValues("age");
        String[]sSex=req.getParameterValues("sex");
        String[] sdpet = req.getParameterValues("dept");

        for(int i=0;i<sName.length;i++){
            try{
               boolean adder=new StudentDao().addWay(new String (sName[i].getBytes("ISO-8859-1"),"UTF-8"),sAge[i],sSex[i],sdpet[i]);
               if(adder){
                   req.getRequestDispatcher("/view").forward(req,resp);
               }
            } catch (SQLException e) {
                e.printStackTrace();
            } catch (NamingException e) {
                e.printStackTrace();
            }
        }

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req,resp);
    }
}
